package com.teach;

import java.util.Scanner;

public class Demo03 {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		System.out.println("请输入一段文字:");
		String str = scanner.nextLine();
		System.out.println("统计结果:");
		int[] r = count(str);
		System.out.println("数字:"+r[0]);
		System.out.println("大写字母:"+r[1]);
		System.out.println("小写字母:"+r[2]);
		System.out.println("中文字符:"+r[3]);
		System.out.println("空格字符:"+r[4]);
		System.out.println("其它字符:"+r[5]);
	}
	
	/**
	 * 
	 * @param str
	 * @return
	 */
	public static int[] count(String str) {
		int[] r = new int[6];
		if (str == null || "".equals(str)) {
			return r;
		}
		
		char[] cs = str.toCharArray();
		for(char c : cs) {
			if(Character.isDigit(c)) {
				r[0]++;
			}else if(Character.isUpperCase(c)) {
				r[1]++;
			}else if(Character.isLowerCase(c)) {
				r[2]++;
			}else if(c>='\u4e00' && c <= '\u9fa5') {
				r[3]++;
			}else if(c == ' ') {
				r[4]++;
			}else {
				r[5]++;
			}
		}
		
		return r;
	}
}
